package com.dyz.swordFingerOffer;

import java.util.Arrays;

/**
 * @author: daiyizheng
 * @date: 2021/6/10 23:47
 * @description:
 */
public class IsContinuous61 {
    public boolean IsContinuous(int [] numbers) {
        //首先统计0的个数
        //看左右区间差值大于1的是否需要0填充，
        //当填充0的个数大于数组中0的个数且数组中有相同值，返回false
        //其他返回true
        if(numbers.length==0){
            return false;
        }
        int sum = 0;
        for (int v: numbers){
            if(v==0){
                sum++;
            }
        }

        Arrays.sort(numbers);
        for(int i = sum+1; i< numbers.length;i++){
            int n = numbers[i] - numbers[i-1]-1;
            sum = sum-n;
            if(sum<0 || numbers[i] == numbers[i-1]){
                return false;
            }
        }
        return true;
    }
}
